import linear.linear;
import node.node;

import java.util.Scanner;

public class App {
    private static Scanner reader;

    public static void main(String[] args) {
        reader = new Scanner(System.in);
        linear linear = new linear();
        while (true) {
            System.out.println("请选择操作类型：(1:添加,2:删除,3:查找,4:排序,5:打印,6:修改,7:退出)");
            int type = reader.nextInt();
            switch (type) {
                case 1:
                    System.out.println("请输入ID:");
                    int id = reader.nextInt();
                    System.out.println("请输入姓名:");
                    String name = reader.next();
                    System.out.println("请输入年龄:");
                    int age = reader.nextInt();
                    linear.add(new node(name, id, age));
                    break;
                case 2:
                    System.out.println("请输入ID:");
                    id = reader.nextInt();
                    linear.delete(id);
                    break;
                case 3:
                    System.out.println("请输入ID:");
                    id = reader.nextInt();
                    System.out.println(linear.find(id));
                    break;
                case 4:
                    System.out.println("请输入排序类型：(1:按ID排序,2:按年龄排序)");
                    int sortType = reader.nextInt();
                    switch (sortType) {
                        case 1:
                            linear.sortById();
                            linear.print();
                            break;
                        case 2:
                            linear.sortByAge();
                            linear.print();
                            break;
                        default:
                            System.out.println("输入错误");
                            break;
                    }
                    break;
                case 5:
                    linear.print();
                    break;
                case 6:
                    System.out.println("请输入ID:");
                    id = reader.nextInt();
                    System.out.println("请输入姓名:");
                    name = reader.next();
                    System.out.println("请输入年龄:");
                    age = reader.nextInt();
                    linear.update(id, name, age);
                    break;
                case 7:
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入错误");
                    break;
            }
        }
    }
}
